﻿<%@ Control Language="C#" EnableViewState="true" %>
<%@ Register Assembly="Antu.WebControls" Namespace="Antu.WebControls" TagPrefix="CBW" %>

<script type="text/javascript">
    var temp, temp2, cookieArray, cookieArray2, cookieCount;

    function onClickForTree(orderId, depName, departId) {
        parent.frames["ifm"].location = "DepartEdit.aspx?orderId=" + orderId + "&depName=" + escape(depName) + "&departId=" + departId;
    }

    function initiate() {

        cookieCount = 0;

        if (document.cookie) {

            cookieArray = new Array();
            cookieArray2 = new Array();
        }

        temp = document.getElementById("containerul");

        for (var o = 0; o < temp.getElementsByTagName("li").length; o++) {

            if (temp.getElementsByTagName("li")[o].getElementsByTagName("ul").length > 0) {

                temp2 = document.createElement("span");
                temp2.className = "symbols";
                temp2.style.backgroundImage = (cookieArray.length > 0) ? ((cookieArray[cookieCount] == "true") ? "url(tree/minus.png)" : "url(tree/plus.png)") : "url(tree/plus.png)";
                temp2.onclick = function() {
                    showhide(this.parentNode);
                    writeCookie();
                }

                temp.getElementsByTagName("li")[o].insertBefore(temp2, temp.getElementsByTagName("li")[o].firstChild)

                temp.getElementsByTagName("li")[o].getElementsByTagName("ul")[0].style.display = "none";

                if (cookieArray[cookieCount] == "true") {
                    showhide(temp.getElementsByTagName("li")[o]);
                }

                cookieCount++;

            } else {

                temp2 = document.createElement("span");
                temp2.className = "symbols";
                temp2.style.backgroundImage = "url(tree/page.png)";

                temp.getElementsByTagName("li")[o].insertBefore(temp2, temp.getElementsByTagName("li")[o].firstChild);
            }
        }
    }

    function showhide(el) {

        el.getElementsByTagName("ul")[0].style.display = (el.getElementsByTagName("ul")[0].style.display == "block") ? "none" : "block";

        el.getElementsByTagName("span")[0].style.backgroundImage = (el.getElementsByTagName("ul")[0].style.display == "block") ? "url(tree/minus.png)" : "url(tree/plus.png)";

    }



    function writeCookie() {		

        cookieArray = new Array()

        for (var q = 0; q < temp.getElementsByTagName("li").length; q++) {

            if (temp.getElementsByTagName("li")[q].childNodes.length > 0) {
                if (temp.getElementsByTagName("li")[q].childNodes[0].nodeName == "SPAN" && temp.getElementsByTagName("li")[q].getElementsByTagName("ul").length > 0) {

                    cookieArray[cookieArray.length] = (temp.getElementsByTagName("li")[q].getElementsByTagName("ul")[0].style.display == "block");

                }
            }

        }

        document.cookie = "state=" + cookieArray.join(",") + ";expires=" + new Date(new Date().getTime() + 365 * 24 * 60 * 60 * 1000).toGMTString();

    }

    function MoveDep(depID, way) {
        document.getElementById('DepID').value = depID;
        document.getElementById('UpDown').value = way;
        form1.submit();
    }
</script>

<input type="hidden" name="displayType" value="" />
<table height="100%" cellspacing="0" cellpadding="0" border="0" class="tab" style="width: 100%">
    <tr>
        <th>
            部门
        </th>
    </tr>
</table>
<input type="hidden" id="DepID" name="DepID" value="" />
<input type="hidden" id="UpDown" name="UpDown" value="" />
<ul id="containerul" style="width: 130px;">
    <CBW:MPRepeater ID="MPRepeater1" runat="server">
        <ItemTemplate>
           <%-- <li style="height: 22px; width:120px; text-align:left;padding-left: 25px;">
            <a href="javascript:onClickForTree('<%#Eval("ORDER_ID") %>','<%#Eval("DEPART_NAME") %>','<%#Eval("DEPARTID") %>');void(0);">
                <%#Eval("DEPART_NAME") %>
            </a></li>
            --%>
            <li style="height: 22px; width:120px; text-align:left;line-height:22px; list-style-type:none; overflow:hidden; 
                font-weight:<%#(Eval("parent_id").ToString() == "0") ? "bold" : ""%>;
                margin-left:<%#(Eval("parent_id").ToString() == "0") ? "5px" : "15px"%>;">
                
            <a href="javascript:onClickForTree('<%#Eval("ORDER_ID") %>','<%#Eval("DEPART_NAME") %>','<%#Eval("DEPARTID") %>');void(0);" title='<%#Eval("DEPART_NAME") %>'>
                <%# ((Eval("DEPART_NAME").ToString()).Length > 10) ? (Eval("DEPART_NAME").ToString()).Substring(0, 10) : (Eval("DEPART_NAME").ToString()) %>
            </a></li>
        </ItemTemplate>
    </CBW:MPRepeater>
</ul>

<script type="text/javascript">
    initiate();
</script>

